package main

import (
	"gitee.com/wm1998/resk/services"
	"github.com/shopspring/decimal"
	"github.com/sirupsen/logrus"
	"net/rpc"
)

// RPC接口客户端代码
func main() {
	c, err := rpc.Dial("tcp", ":18082")
	if err != nil {
		logrus.Panic(err)
	}
	sendout(c)
	receive(c)
}

func sendout(c *rpc.Client) {
	in := services.RedEnvelopeSendingDTO{ // 调用远程RPC用户API方法-入参
		Amount:       decimal.NewFromFloat(1),
		UserId:       "1vsglfVEkjosBBAERLVsGmojujK",
		Username:     "测试用户",
		EnvelopeType: services.GeneralEnvelopeType,
		Quantity:     2,
		Blessing:     "",
	}
	out := &services.RedEnvelopeActivity{} // 调用远程RPC用户API方法-出参

	// 【调用远程RPC用户API方法：apis/gorpc/envelope.go的，参数1：远程方法名称全路径；参数2：输入参数；参数3：输出参数】
	err := c.Call("EnvelopeRpc.SendOut", in, &out)
	if err != nil {
		logrus.Panic(err)
	}

	logrus.Infof("%+v", out)
}

func receive(c *rpc.Client) {
	in := services.RedEnvelopeReceiveDTO{
		EnvelopeNo:   "1vwiHb40LOLp6MkgRXgS3gmeMn7",
		RecvUserId:   "1vwiHUUNkugpFHPjZzOwKTXqmpk",
		RecvUsername: "测试用户1",
		AccountNo:    "1vwiHT9jgJgxVVXoCKrExL7lwln",
	}
	out := &services.RedEnvelopeItemDTO{}
	err := c.Call("Envelope.Receive", in, out)
	if err != nil {
		logrus.Panic(err)
	}
	logrus.Infof("%+v", out)
}
